package logic

import (
	"context"
	"errors"
	"meituan_srv/model/redisinit"

	"meituan_srv/internal/svc"
	"meituan_srv/meituan"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCartNumLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateCartNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCartNumLogic {
	return &UpdateCartNumLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 购物车更新
func (l *UpdateCartNumLogic) UpdateCartNum(in *meituan.UpdateCartNumRequest) (*meituan.UpdateCartNumResponse, error) {
	// todo: add your logic here and delete this line

	err := redisinit.UpdateCartNum(in.UserId, in.MeiTuanId, in.Num)
	if err != nil {
		logx.Error("购物车更新失败")
		return nil, errors.New("购物车更新失败")
	}
	return &meituan.UpdateCartNumResponse{}, nil
}
